#!/usr/bin/env python
# _*_ coding: utf-8 _*_
# @Time : 2021/6/24 14:25
# @Author : haoaremesda
# @Version：V 0.1
# @File : yzm_6,24.py
# @desc :
import requests
import json
import time
import os
# 建立请求头
list_b = []
list_c=[]
sess = requests.Session()
headers = {
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36",
    "Referrer":"strict-origin-when-cross-origin"
}
def tp_loard(i):
    now = int(time.time())
    url='https://verify.snssdk.com/captcha/get?lang=zh&app_name=acweb&h5_sdk_version=2.17.2&sdk_version=&iid=0&did=0&device_id=0&ch=web_text&aid=4272&os_type=2&mode=slide&tmp={now}&platform=pc&webdriver=false&fp=verify_365862e8ba39dde7c14ee89a871702f5&type=verify&detail=-a4b*8TGolywXG0f*PcSQV-QfH0N78GL4xj3sbKA5SkRVQMZ-o4qgS6N4fe34UJNb1si22yCxpRvzg99J5vAgzxfqlNu-oHFHZqJ3RnY*24xHCivi9hOYJFgoK5s3klQevjnCFlcWTddeFrokhonfkG6lR84wro1Yc987qqd6bxP5KVULHJuTyojZ6Da2FUD9fLYrl9ODeTLU08VVN9DX00Lha7d2nu1RtRdOW6ZnM68XW1haIIHEFT0QTBJ5OvJNmWEDCiWQ8XszOdyGrtvmIC*bTsKnqxeIi1XTmziGoDTi-vWtfryPvRfGNmPD6jKbPIipryuj0rYLYgvmGx3OZi7XzPkqfp*ZqkpAiNmsMRGal*AvLbSIBbCqB8zAQRlbJHM*sSv4aVlDETNDequois7aTzIQIOeiFaP2NIcCKz30ISlUsUgrIreFxVxlhjY3jCP&subtype=slide&challenge_code=99999&os_name=windows'
    try:
        req = requests.get(url)
        content = json.loads(req.text)
    # print(req.status_code)
        #提取图片url接口
        list_b.append(content['data']['question']["url1"])
        list_c.append(content['data']['question']['url2'])
        print(list_b)
        print(list_c)
    except Exception as e:#捕捉异常并处理，处理方式就是重新执行tp_loard(i)函数
        return tp_loard(i)
        print('异常' + str(e))
    root = "D://tp//"
    path = root + str(i) + ".jpg"
    path2 = root + '0' + str(i) + ".jpg"
    for new_b in list_b :
        url = new_b
        # print(url)
        # 获取响应图片内容
        image = sess.get(url, headers=headers).content
        path1 = root +str(i) + ".jpg"
        with open(root+str(i)+'.jpg','wb') as f:
            f.write(image)
    for new_c in list_c:
        url_c = new_c
        # print(url_c)
        # 获取响应图片内容
        image = sess.get(url_c, headers=headers).content
        with open(path2, 'wb') as f:
            f.write(image)
if __name__ == '__main__':
    for i in range(1,1001):
        tp_loard(i)
        # time.sleep(random.random()*5)
        if i % 9 == 0:
            time.sleep(2)
        print('第{}组图片保留下来了'.format(i))
        print(time.time())
